package com.crm.pojo.common;


import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T>Result<T> success(T data, Integer code,String message){
        return restResult(data, code,  message);
    }

    public static <T>Result<T> success(){
        return restResult(null, 200, "操作成功");
    }

    public static <T>Result<T> success(T data){
        return restResult(data, 200,  "操作成功");
    }

    public static <T>Result<T> success(T data, int code, String message){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    public static <T>Result<T> fail(T data){
        Result<T> result = new Result<>();
        result.setCode(500);
        result.setMessage(data.toString());
        return result;
    }




    private static <T> Result<T> restResult(T data, Integer code, String message) {
         Result<T> apiResult = new Result<>();
         apiResult.setCode(code);
         apiResult.setMessage(message);
         apiResult.setData(data);
         return apiResult;
    }


    // 新增的 error 方法
    public static <T>Result<T> error() {
        return restResult(null, 500, "操作失败");
    }

    public static <T>Result<T> error(String message) {
        return restResult(null, 500, message);
    }

}
